﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Windows.Media.Animation;
using Douban.Modules.Conversation.ViewModels;

namespace Douban.Modules.Conversation.Views
{
	/// <summary>
	/// Interaction logic for ConversationShellView.xaml
	/// </summary>
	public partial class ConversationShellView : IConversationShellView
	{
		public ConversationShellView()
		{
			this.InitializeComponent();

            this.Owner = Application.Current.MainWindow;
        }

        #region IConversationView Members

        public IConversationShellViewModel Context
        {
            get
            {
                return this.DataContext as IConversationShellViewModel;
            }
            set
            {
                this.DataContext = value;
            }
        }

        public double ShellWidth
        {
            get { return this.Width; }
            set { this.Width = value; }
        }

        public void ShowView()
        {
            this.Show();
        }

        public void CloseView()
        {
            DoubleAnimation closeAnimation = new DoubleAnimation();
            closeAnimation.From = 1;
            closeAnimation.To = 0;
            closeAnimation.Duration = TimeSpan.FromMilliseconds(300);
            closeAnimation.Completed += (sender, e) => this.Close();
            this.BeginAnimation(OpacityProperty, closeAnimation);
        }

        public void MinimizeView()
        {
            this.WindowState = System.Windows.WindowState.Minimized;
        }

        public void RecoverView()
        {
            this.WindowState = WindowState.Normal;
        }

        #endregion

        private void BorderlessWindow_Loaded(object sender, RoutedEventArgs e)
        {
            var header = (Panel)this.FindName("PART_Header");
            if (header != null)
                header.MouseLeftButtonDown += (obj, args) => this.DragMove();
        }
    }
}